package org.example;

public class 第二十章_异常处理 {
    public static void main(String[] args) throws Exception {
        //try/catch/finally
        try {
            int u = 1/0;
        }catch (Exception e){
            System.out.println("出现异常");
        }finally {
            System.out.println("执行了finally");
        }

        //throw 抛出异常
        if(1<2){
            throw new InsufficientFundsException(1);
//            throw new Exception("1111111");
        }
    }

    //自定义异常
    static class InsufficientFundsException extends Exception
    {
        //此处的amount用来储存当出现异常（取出钱多于余额时）所缺乏的钱
        private double amount;
        public InsufficientFundsException(double amount)
        {
            this.amount = amount;
        }
        public double getAmount()
        {
            return amount;
        }
    }
}
